package com.jh3502.helper.function.home;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.jh3502.helper.BuildConfig;
import com.jh3502.helper.R;
import com.jh3502.helper.base.BaseActivity;
import com.jh3502.helper.function.login.LoginActivity;
import com.jh3502.helper.function.person.personlist.PersonListBean;
import com.jh3502.helper.function.person.personlist.PersonListCheckActivity;
import com.jh3502.helper.function.person.personlist.PersonListFragment;
import com.jh3502.helper.utils.ActivityTracker;
import com.jh3502.helper.utils.SpHelper;
import com.jh3502.helper.utils.Utils;
import com.jh3502.helper.view.RoundImageView;
import com.jh3502.helper.view.SnackbarUtil;

import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.OnClick;

public class HomeActivity extends BaseActivity implements HomePresenter.HomeView {
    @BindView(R.id.home_version)
    TextView homeVersion;
    @BindView(R.id.home_head)
    RoundImageView homeHead;
    @BindView(R.id.home_name)
    TextView homeName;
    private HomePresenter homePresenter;

    @Override
    protected int setViewId() {
        return R.layout.activity_home;
    }

    @Override
    protected void initView() {
        homeVersion.setText(getResources().getString(R.string.app_name) + BuildConfig.VERSION_NAME);
        homeName.setText(SpHelper.getInstance().getString("name"));

        if (!TextUtils.isEmpty(SpHelper.getInstance().getString("method"))) {
            Glide.with(this).load(SpHelper.getInstance().getString("method")).into(homeHead);
        }

        homePresenter = new HomePresenter();
        homePresenter.setHomeView(this);
        homePresenter.toVersion();

//        TextView textView = null;
//        textView.setText("6666");
//        String url = "https://github.com/trazyn/ieaseMusic/releases/download/v1.2.3/ieaseMusic-1.2.3-mac.dmg";
//        new VersionUpdataHelper(this, url);
//        List<PersonListBean> list = new ArrayList<>(2);
//        for(int i= 0;i<10;i++){
//            PersonListBean personListBean = new PersonListBean();
//            personListBean.setName(i+"");
//            list.add(personListBean);
//        }
//        PersonListBean temp = list.get(2);
//        temp.setName("666");
//        Log.e("3502",list.toString());


        /*showLongToast("aaa", "确定", new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(HomeActivity.this,"harisucuci", Toast.LENGTH_LONG).show();
            }
        }, SnackbarUtil.ALERT);*/
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void doOnDestroy() {

    }

    @Override
    protected void doOnResume() {

    }

    @Override
    protected void doOnSaveInstanceState(Bundle savedInstanceState) {

    }

    @Override
    public void responseError(int code, String msg) {

    }


    @Override
    public void gettetiSuccess() {
        showShortToast("特体列表更新成功");
    }

    @Override
    public void listltruleSuccess() {
        showShortToast("一般号型更新成功");
    }

    @Override
    public void ltShapeRuleSuccess() {
        showShortToast("ABC号型更新成功");
    }

    @Override
    public void versionSuccess(@NonNull Map<String, Object> map) {
        int versionNet = Integer.parseInt((String) map.get("version"));
        int version = BuildConfig.VERSION_CODE;
        String name = BuildConfig.VERSION_NAME;

    }

    @OnClick(R.id.home_tab_icon_my_task)
    public void onHomeTabIconMyTaskClicked() {
        String batAct = SpHelper.getInstance().getBatAct();
        if (TextUtils.isEmpty(batAct)) {
            showShortToast("没有首选任务");
            return;
        }
        Utils.getInstance().startActivity(this, PersonListFragment.class, false);
    }

    @OnClick(R.id.home_tab_icon_data_collection)
    public void onHomeTabIconDataCollectionClicked() {
    }

    @OnClick(R.id.home_tab_icon_data_sorting)
    public void onHomeTabIconDataSortingClicked() {
        String batAct = SpHelper.getInstance().getBatAct();
        if (TextUtils.isEmpty(batAct)) {
            showShortToast("没有首选任务");
            return;
        }
        Map<String, Object> batInfo = Utils.getInstance().jso2map(SpHelper.getInstance().getBatAct());
        List<PersonListBean> personListAll = SpHelper.getInstance().getPersonList((String) batInfo.get("batno"));
        if (personListAll == null) {
            showShortToast("活动任务没数据", SnackbarUtil.ALERT);
            return;
        }
        Utils.getInstance().startActivity(this, PersonListCheckActivity.class, false);
    }

    @OnClick(R.id.home_tab_icon_task_management)
    public void onHomeTabIconTaskManagementClicked() {
        Utils.getInstance().startActivity(this, HomeMenuActivity.class, false);
    }

    @OnClick(R.id.home_tab_icon_type_standard_management)
    public void onHomeTabIconTypeStandardManagementClicked() {
        homePresenter.toListltrule();
        homePresenter.toGetteti();
        homePresenter.toLtShapeRule();
    }

    @OnClick(R.id.home_tab_icon_system_settings)
    public void onHomeTabIconSystemSettingsClicked() {
    }


    @OnClick(R.id.home_logout)
    public void onViewClicked() {
        SpHelper.getInstance().clearAll();
        ActivityTracker.getInstance().finishAll();
        Utils.getInstance().startActivity(this, LoginActivity.class);
    }
}
